package com.checkoutcheckins.client.panels;

import com.checkoutcheckins.client.data.foursquare.Badge;
import com.checkoutcheckins.client.data.foursquare.FoursquareUser;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.VerticalPanel;

public class BadgesPanel extends VerticalPanel {

	public BadgesPanel(FoursquareUser fsUser) {
		super();
		init(fsUser);
	}

	private void init(FoursquareUser fsUser) {

		FlexTable badgesTable = new FlexTable();
		badgesTable.setCellSpacing(3);
		badgesTable.setWidth("100%");

		if (fsUser.getBadges() != null) {

			int item = 0;

			for (Badge b : fsUser.getBadges()) {
				VerticalPanel badge = new VerticalPanel();
				badge.setStyleName("center");
				Image badgeIcon = new Image(b.getIcon());
				badgeIcon.setTitle(b.getDescription());
				badge.add(badgeIcon);
				HTML badgeTitle = new HTML(b.getName());
				badgeTitle.setStyleName("seventy");
				badgeTitle.addStyleName("center");
				badge.add(badgeTitle);
				badgesTable.setWidget(item / 4, item % 4, badge);
				item++;
			}

			this.setStyleName("badgesPanel");
			this.add(badgesTable);
		}
		else
		{
			this.add(new HTML("You have no badges at this time.  Keep at it!"));
		}
	}

}
